﻿<!DOCTYPE html>
<html>
<head>
<!--
  Copyright (c) 2017-2018 Jean-Marc VIGLINO,
  released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
-->
  <title>ol-ext: Measure tooltips</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta name="description" content="A ttoltips to display information (measure) on a feature." />
  <meta name="keywords" content="ol, overlay, popup, vector, feature, tooltips" />

  <!-- FontAwesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

  <!-- jQuery -->
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>

  <!-- Openlayers -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@latest/ol.css" />
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@latest/dist/ol.js"></script>

  
  <!-- ol-ext -->
  <link rel="stylesheet" href="../../dist/ol-ext.css" />
  <script type="text/javascript" src="../../dist/ol-ext.js"></script>
  <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
  <script src="https://unpkg.com/elm-pep"></script>

  <link rel="stylesheet" href="../style.css"/>
  <style>
    .ol-popup h1 {
      font-size: 1em;
      background-size: 2em;
      padding-left: 3em;
    }
  </style>
</head>
<body >
  <a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>
  <a href="../../index.html">
    <h1>ol-ext: Measure tooltips</h1>
  </a>

  <div class="info">
    <i>ol/Overlay/Tooltips</i> is a popup to display information on the fly.
    <br/>
    This example shows how to display measure informations while drawing.
    <ul>
      <li>
        You can link a <i>ol.Feature</i> using <i>setFeature()</i> method to display information about the feature (measure).
      </li><li>
        Overwrite the <i>getHTML()</i> method to show your own feature information.
      </li><li>
        Overwrite the <i>formatLength()</i> or <i>formatArea</i> method to change measure units.
      </li>
    </ul>
    The <a href="../bar/map.control.editbar.html">Edit bar example</a> show how to show information while editing.
  </div>

  <!-- DIV pour la carte -->
  <div id="map" style="width:600px; height:400px;"></div>

  <div class="options" style="max-width:20em;">
    <h2>Options:</h2>
    <ul>
      <li>
        <label><input name="type" type="radio" checked="checked" onchange="drawPoly.setActive(false); drawLine.setActive(true); " /> distance</label>
        <label><input name="type" type="radio" onchange="drawPoly.setActive(true); drawLine.setActive(false); " /> area</label>
      </li>
    </ul>
  </div>
  
  <script type="text/javascript">
  // Layers
  var layers = [ new ol.layer.Geoportail({ layer: 'ORTHOIMAGERY.ORTHOPHOTOS' }) ]

  // The map
  var map = new ol.Map({
    target: 'map',
    view: new ol.View({
      zoom: 5,
      center: [166326, 5992663]
    }),
    layers: layers
  });

  var drawLine = new ol.interaction.Draw({ type: 'LineString' });
  map.addInteraction(drawLine);
  var drawPoly = new ol.interaction.Draw({ type: 'Polygon' });
  map.addInteraction(drawPoly);
  drawPoly.setActive(false);

  // Add a tooltip
  var tooltip = new ol.Overlay.Tooltip();
  map.addOverlay(tooltip);

  // Set feature on drawstart
  drawLine.on('drawstart', tooltip.setFeature.bind(tooltip));
  // Remove feature on finish
  drawLine.on(['change:active','drawend'], tooltip.removeFeature.bind(tooltip));

  // Set feature on drawstart
  drawPoly.on('drawstart', tooltip.setFeature.bind(tooltip));
  // Remove feature on finish
  drawPoly.on(['change:active','drawend'], tooltip.removeFeature.bind(tooltip));

  </script>
  
</body>
</html>